Page({

    /**
     * 页面的初始数据
     */
    data: {
        mes: {
            type: '',  //消息提示类型
            showMessage: false,
            text: '',   //消息提示内容,
            icon: ''   //图标
        },
        status: '',
        message: {},
        show: false
    },
    gotoChat() {
        const that = this
        wx.navigateTo({
            url: '/pages/message/chatroom/chatroom',
            success: function (res) {
                // 通过eventChannel向被打开页面传送数据
                res.eventChannel.emit('details_chatroom', that.data.message)
            }
        })
    },
    want() {
        wx.showToast({
            title: '请联系对方',
            icon: 'none',
            duration: 2000
        })
    },
    procedure() {
        if (this.data.show) {
            this.setData({
                show: false
            })
        } else {
            this.setData({
                show: true
            })
        }

    },
    del() {
        wx.showModal({
            title: '提示',
            content: '确定删除',
            success(res) {
                if (res.confirm) {
                    let dataList = {}
                    dataList._id = this.data.message._id
                    dataList.type = this.data.message.types
                    wx.cloud.callFunction({
                        name: 'issue',
                        data: {
                            list: dataList,
                        }
                    }).then((data) => {
                        if (data.result == "ok") {
                            wx.navigateBack({
                                delta: 1
                            })
                        } else {//删除失败
                            wx.showToast({
                                title: '错误',
                                icon: 'none',
                                image: '/pages/images/icon/error.png',
                                duration: 2000
                            })
                        }
                    })
                }
            }
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        const eventChannel = this.getOpenerEventChannel();
        eventChannel.on('to_details', (data) => {
            data.mes.time = data.mes.time.slice(0, 10);
            this.setData({
                message: data.mes,
                status: data.status
            })
            this.data.message.types = "lostGoods"

        })

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
        const cur = getCurrentPages()
        if (cur[cur.length - 2].route == "pages/homePage/lostGoods/addlostGoods/addlostGoods") {
            wx.navigateBack({
                delta: 1
            })
        }

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})